﻿//DB Connection
private var dbconn:SQLConnection;
//Query Statement
private var sqlQuery:SQLStatement;		
//Create Table Statement
private var sqlCreateTable:SQLStatement;
//Insert Statement
private var sqlInsert:SQLStatement;
//Import Statement
private var sqlImport:SQLStatement;

//Returned Data
[Bindable] private var sqlData:ArrayCollection;

/**
 * Creates a database connection, registers event listeners, specifies the database filename
 * checks to see if the database exsists, if it does then we connection to it.
 * If it doesnt, then we create a new database file, and create our tables.
 * 
 * @constructor
 */		
public function DatabaseManager()
{
	//Connect to the db
	dbconn = new SQLConnection();
		
	//Add event listener
	dbconn.addEventListener( SQLErrorEvent.ERROR, onSQLError );
	
	//Set the location of the db file				
	var dbFile:File = File.applicationStorageDirectory.resolvePath( "AS3project.db" );
	
	//Check if the db file exsists
	if ( dbFile.exists )
	{
		//Connect to the db then
		dbconn.addEventListener( SQLEvent.OPEN, onSQLOpen );
	} else {
		//Create the db
		dbconn.addEventListener( SQLEvent.OPEN, onSQLCreate );	
	}
	//Execute
	dbconn.openAsync( dbFile );			
}	

